<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/5/15
 * Time: 11:49
 */

namespace Admin\Controller;
use Think\Controller;

class BusinessManController extends CommonController
{
    private $business='';
    private $community='';

    function __construct()
    {
        parent::__construct();
        $this->business=D("Seller");
        $this->community=D('community');
        $this->bussiness->startTrans();
    }

    function index(){
        $yanG1=$this->business->select();
        $data=$yanG1;
        foreach($yanG1 as $key=>$r)
        {
            $data[$key]['add_time']=date("Y-m-d",$r['add_time']);
        }
        $this->assign("data",$data);
        $this->display();
    }

    function addMan()
    {
        if($_POST){

            $data=$_POST;
            $data['id']='';
            $data['add_time']=time();
            $aa=$this->business->data($data)->add();
            if($aa){
                $this->business->commit();
                $this->success("商户添加成功");
            }else{
                $this->business->rollback();
                $this->error("商户添加失败");
            }
        }else{
            $this->display();
        }
    }

    function updataMan($id='')
    {
        if($_POST)
        {
            print_r($_POST);
            echo "<hr>";
            echo "提交修改信息"; exit;
        }else{
            $yanG1=$this->business->where('id='.$id)->find();
            $data=$yanG1;
            $data['add_time']=date("Y-m-d",$yanG1['add_time']);
            $this->assign("data",$data);
            $this->display();
        }
    }

    /*
     * 删除商户信息
     * 此删除为假删除
     * 改变is_detele 这个字段的值
     * */

    function delMan($id='')
    {
        $data['is_delete']="1";    //  当此值为1是  表示删除
        $aa=$this->business->where('id='.$id)->save($data);
        if($aa)
        {
            $this->business->commit();
            $this->success("删除商品成功!!!");
        }else{
            $this->business->rollback();
            $this->error("商品删除失败!!!");
        }
    }

    /*
     * 还原被删除的商户信息(is_delete=1)
     * */
    function restMan($id='')
    {
        $data['is_delete']='0';
        $aa=$this->business->where('id='.$id)->save($data);
        if($aa)
        {
            $this->business->commit();
            $this->success("还原商品成功!!!");
        }else{
            $this->business->rollback();
            $this->error("还原商品失败!!!");
        }
    }
}
